scriptDir   := A_ScriptDir
ConfigFile  := scriptDir "\..\config\config.ini"
mouse       := scriptDir "\..\config\mouse.ini"
key_M4A4    := IniRead(ConfigFile, "KeyBinds", "M4A4")
key_M4A1    := IniRead(ConfigFile, "KeyBinds", "M4A1")
key_Famas   := IniRead(ConfigFile, "KeyBinds", "Famas")
key_AUG     := IniRead(ConfigFile, "KeyBinds", "AUG")
key_AK      := IniRead(ConfigFile, "KeyBinds", "AK")
key_Galil   := IniRead(ConfigFile, "KeyBinds", "Galil")
key_SG      := IniRead(ConfigFile, "KeyBinds", "SG")
key_UMP     := IniRead(ConfigFile, "KeyBinds", "UMP")

key_off     := IniRead(ConfigFile, "KeyBinds", "off")
key_exit    := IniRead(ConfigFile, "KeyBinds", "exit")

key_shoot   := IniRead(mouse, "KeyBinds", "shoot")
key_zoom    := IniRead(ConfigFile, "KeyBinds", "zoom")
sens        := IniRead(ConfigFile, "Settings", "sens")
zoomsens    := IniRead(ConfigFile, "Settings", "zoomsens")
PauseKey    := IniRead(mouse, "Controls", "PauseKey")

;   平滑系数
smoothness := 0.7
;   变焦调整系数
modifier := 2.52/sens

;   压枪时的X，Y移动因子
AK_Move_Factor := [ [-4, 7],
                    [4, 19],
                    [-3, 29],
                    [-1, 31],
                    [13, 31],
                    [8, 28],
                    [13, 21],
                    [-17, 12],
                    [-42, -3],
                    [-21, 2],
                    [12, 11],
                    [-15, 7],
                    [-26, -8],
                    [-3, 4],
                    [40, 1],
                    [19, 7],
                    [14, 10],
                    [27, 0],
                    [33, -10],
                    [-21, -2],
                    [7, 3],
                    [-7, 9],
                    [-8, 4],
                    [19, -3],
                    [5, 6],
                    [-20, -1],
                    [-33, -4],
                    [-45, -21],
                    [-14, 1]]

m4a1_Move_Factor:=[ [1, 6],
                    [0, 4],
                    [-4,14],
                    [4, 18],
                    [-6, 21],
                    [-4, 24],
                    [14, 14],
                    [8, 12],
                    [18, 5],
                    [-4, 10],
                    [-14, 5],
                    [-25, -3],
                    [-19, 0],
                    [-22, -3],
                    [1, 3],
                    [8, 3],
                    [-9, 1],
                    [-13, -2],
                    [3, 2],
                    [1, 1]]

m4a4_Move_Factor:=[ [2, 7],
                    [0, 9],
                    [-6, 16],
                    [7, 21],
                    [-9, 23],
                    [-5, 27],
                    [16, 15],
                    [11, 13],
                    [22, 5],
                    [-4, 11],
                    [-18, 6],
                    [-30, -4],
                    [-24, 0],
                    [-25, -6],
                    [0, 4],
                    [8, 4],
                    [-11, 1],
                    [-13, -2],
                    [2, 2],
                    [33, -1],
                    [10, 6],
                    [27, 3],
                    [10, 2],
                    [11, 0],
                    [-12, 0],
                    [6, 5],
                    [4, 5],
                    [3, 1],
                    [4, -1]]

famas_Move_Factor := [[-4, 5],
                    [1, 4],
                    [-6, 10],
                    [-1, 17],
                    [0, 20],
                    [14, 18],
                    [16, 12],
                    [-6, 12],
                    [-20, 8],
                    [-16, 5],
                    [-13, 2],
                    [4, 5],
                    [23, 4],
                    [12, 6],
                    [20, -3],
                    [5, 0],
                    [15, 0],
                    [3, 5],
                    [-4, 3],
                    [-25, -1],
                    [-3, 2],
                    [11, 0],
                    [15, -7],
                    [15, -10]]

galil_Move_Factor := [[4, 4],
                    [-2, 5],
                    [6, 10],
                    [12, 15],
                    [-1, 21],
                    [2, 24],
                    [6,16],
                    [11, 10],
                    [-4, 14],
                    [-22, 8],
                    [-30, -3],
                    [-29, -13],
                    [-9, 8],
                    [-12, 2],
                    [-7, 1],
                    [0, 1],
                    [4, 7],
                    [25, 7],
                    [14, 4],
                    [25, -3],
                    [31, -9],
                    [6, 3],
                    [-12, 3],
                    [13, -1],
                    [10,-1],
                    [16, -4]]

ump_Move_Factor := [[-1, 6],
                    [-4, 8],
                    [-2, 18],
                    [-4, 23],
                    [-9. 23],
                    [-3, 26],
                    [11, 17],
                    [-4, 12],
                    [9, 13],
                    [18, 8],
                    [15, 5],
                    [-1, 3],
                    [5, 6],
                    [0, 6],
                    [9, -3],
                    [5, -1],
                    [-12, 4],
                    [-19, 1],
                    [-1, -2],
                    [15, -5],
                    [17, -2],
                    [-6, 3],
                    [-20, -2],
                    [-3, -1]]

aug_Move_Factor := [[5, 6],
                    [0, 13],
                    [-5, 22],
                    [-7, 26],
                    [5, 29],
                    [9, 30],
                    [14, 21],
                    [6, 15],
                    [14, 13],
                    [-16, 11],
                    [-5, 6],
                    [13, 0],
                    [1, 6],
                    [-22, 5],
                    [-38, -11],
                    [-31, -13],
                    [-3, 6],
                    [-5, 5],
                    [-9, 0],
                    [24, 1],
                    [32, 3],
                    [15, 6],
                    [-5, 1],
                    [17, -3],
                    [29, -11],
                    [19, 0],
                    [-16, 6],
                    [-16, 3],
                    [-4, 1]]

sg_Move_Factor := [[-4, 9],
                    [-13, 15],
                    [-9, 25],
                    [-6, 29],
                    [-8, 31],
                    [-7, 36],
                    [-20, 14],
                    [14, 17],
                    [-8, 12],
                    [-15, 8],
                    [-5, 5],
                    [6, 5],
                    [-8, 6],
                    [2, 11],
                    [-14, -6],
                    [-20, -17],
                    [-18, -9],
                    [-8, -2],
                    [41, 3],
                    [56, -5],
                    [43, -1],
                    [18, 9],
                    [14, 9],
                    [6, 7],
                    [21, -3],
                    [29, -4],
                    [-6, 8],
                    [-15, 5],
                    [-38, -5]]

;   两次射击之间的间隔时间
AK_Sleep    := [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 0]
M4A4_Sleep  := [88, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 87, 87, 87, 87, 0]
famas_Sleep := [88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 87, 88, 88, 88, 88, 88, 80, 88, 80, 84, 80, 88, 88]
ump_Sleep   := [90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 85, 90, 90, 85, 90, 90, 90]
aug_Sleep   := [89, 89, 89, 88, 88, 80, 80, 89, 88, 89, 89, 88, 89, 88, 89, 89, 88, 89, 88, 89, 88, 89, 88, 89, 95, 89, 89, 89, 89]
sg_Sleep    := [89, 89, 89, 88, 88, 80, 80, 89, 88, 89, 89, 88, 89, 88, 89, 89, 88, 89, 88, 89, 88, 89, 88, 89, 95, 89, 89, 89, 89]

;   初始值不启动任何武器
ak      :=false
m4a1    :=false
m4a4    :=false
famas   :=false
galil   :=false
ump     :=false
aug     :=false
sg      :=false

;   初始值状态：正常运行
Paused := false

if (PauseKey = "")
{
    PauseKey := "F12"
}

loop
{
    sleep 1

    if GetKeyState(PauseKey, "P")
    {
        Paused := !Paused
        Sleep 200
    }

    if (! Paused)
    {

        if GetKeyState(key_AK)
        {
            SoundPlay scriptDir "\..\music\1.mp3"
            ak      :=true
            m4a1    :=false
            m4a4    :=false
            famas   :=false
            galil   :=false
            ump     :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_M4A1)
        {
            SoundPlay scriptDir "\..\music\2.mp3"
            m4a1    :=true
            ak      :=false
            m4a4    :=false
            famas   :=false
            galil   :=false
            ump     :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_M4A4)
        {
            SoundPlay scriptDir "\..\music\3.mp3"
            m4a4    :=true
            ak      :=false
            m4a1    :=false
            famas   :=false
            galil   :=false
            ump     :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_Famas)
        {
            SoundPlay scriptDir "\..\music\4.mp3"
            famas   :=true
            ak      :=false
            m4a1    :=false
            m4a4    :=false
            galil   :=false
            ump     :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_Galil)
        {
            SoundPlay scriptDir "\..\music\5.mp3"
            galil   :=true
            ak      :=false
            m4a1    :=false
            m4a4    :=false
            famas   :=false
            ump     :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_exit)
        {
            SoundPlay scriptDir "\..\music\8.mp3"
            sleep 2000
            ExitApp
        }

        if GetKeyState(key_off)
        {
            SoundPlay scriptDir "\..\music\7.mp3"
            ak      :=false
            m4a1    :=false
            m4a4    :=false
            famas   :=false
            galil   :=false
            ump     :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_UMP)
        {
            SoundPlay scriptDir "\..\music\6.mp3"
            ump     :=true
            ak      :=false
            m4a1    :=false
            m4a4    :=false
            famas   :=false
            galil   :=false
            aug     :=false
            sg      :=false
        }

        if GetKeyState(key_SG)
        {
            SoundPlay scriptDir "\..\music\9.mp3"
            sg      :=true
            ump     :=false
            ak      :=false
            m4a1    :=false
            m4a4    :=false
            famas   :=false
            galil   :=false
            aug     :=false
        }

        if GetKeyState(key_AUG)
        {
            SoundPlay scriptDir "\..\music\10.mp3"
            aug     :=true
            ump     :=false
            ak      :=false
            m4a1    :=false
            m4a4    :=false
            famas   :=false
            galil   :=false
            sg      :=false
        }

        if GetKeyState(key_shoot)
        {
            ;--------------------------------AK-47--------------------------------

            if ak
            {
                loop
                {
                    Click 0, 0, "Relative Down"
                    Sleep 50
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop ak_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(ak_Move_Factor[A_Index][1] * modifier), Integer(ak_Move_Factor[A_Index][2] * modifier), smoothness)
                        sleep AK_Sleep[A_Index]
                        if !GetKeyState(key_shoot)
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }

                    Sleep 80
                    Click 0, 0, "Relative Up"
                    Sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }
            ;--------------------------------M4A1-S--------------------------------

            else if m4a1
            {
                loop
                {
                    Click 0, 0, "Relative Down"
                    sleep 15
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop m4a1_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(m4a1_Move_Factor[A_Index][1] * modifier), Integer(m4a1_Move_Factor[A_Index][2] * modifier), smoothness)
                        sleep 88
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }

                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }

            ;--------------------------------M4A4--------------------------------

            else if m4a4
            {
                loop
                {
                    Click 0, 0, "Relative Down"
                    sleep 15
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop m4a4_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(m4a4_Move_Factor[A_Index][1] * modifier), Integer(m4a4_Move_Factor[A_Index][2] * modifier), smoothness)
                        sleep M4A4_Sleep[A_Index]
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }

                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }

            ;--------------------------------Famas--------------------------------

            else if famas 
            {
                loop
                {
                    Click 0, 0, "Relative Down"
                    sleep 30
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop famas_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(famas_Move_Factor[A_Index][1] * modifier), Integer(famas_Move_Factor[A_Index][2] * modifier), smoothness)
                        sleep M4A4_Sleep[A_Index]
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }

                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }

            ;--------------------------------Galil--------------------------------

            else if galil {
                loop {
                    Click 0, 0, "Relative Down"
                    sleep 10
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop galil_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(galil_Move_Factor[A_Index][1] * modifier), Integer(galil_Move_Factor[A_Index][2] * modifier), smoothness)
                        sleep 90
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }
                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }
            ;--------------------------------UMP-45--------------------------------

            else if ump {
                loop {
                    Click 0, 0, "Relative Down"
                    sleep 15
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop ump_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(ump_Move_Factor[A_Index][1] * modifier), Integer(ump_Move_Factor[A_Index][2] * modifier), smoothness)
                        sleep ump_Sleep[A_Index]
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }

                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }
            ;--------------------------------AUG--------------------------------

            else if aug
            {
                if GetKeyState(key_zoom)
                {
                    zom := 1.2 / zoomsens
                }
                else
                {
                    zom := 1
                }

                loop {
                    Click 0, 0, "Relative Down"
                    sleep 30
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop aug_Move_Factor.Length
                    {
                        SmoothMouseMove(Integer(aug_Move_Factor[A_Index][1] * modifier * zom), Integer(aug_Move_Factor[A_Index][2] * modifier * zom), smoothness)
                        sleep aug_Sleep[A_Index]
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }

                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }

            ;--------------------------------SG 553--------------------------------

            else if sg 
            {
                if GetKeyState(key_zoom)
                {
                    zom := 1.2 / zoomsens
                } 
                else
                {
                    zom := 1
                }

                loop
                {
                    Click 0, 0, "Relative Down"
                    sleep 30
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }

                    loop sg_Move_Factor.Length
                    {
                        MouseMove(Integer(sg_Move_Factor[A_Index][1] * modifier * zom), Integer(sg_Move_Factor[A_Index][2] * modifier * zom), 0, "R")
                        sleep sg_Sleep[A_Index]
                        if !GetKeyState(key_shoot) 
                        {
                            Click 0, 0, "Relative Up"
                            break
                        }
                    }
                    
                    Click 0, 0, "Relative Up"
                    sleep 1000
                    if !GetKeyState(key_shoot) 
                    {
                        Click 0, 0, "Relative Up"
                        break
                    }
                }
            }
        }
    }
}

SmoothMouseMove(x, y, smoothness)
{
    steps := 2.6  
    stepSizeX := x / steps
    stepSizeY := y / steps
    sleepTime := 1

    Loop Integer(steps)
    {
        x := x - stepSizeX
        y := y - stepSizeY
        ;   MouseMove X, Y , [Speed, Relative]
        ;   speed : range 0 (fastest) to 100 (slowest), default 2
        MouseMove x, y, 0, "R"
        ; DllCall("mouse_event", "UInt", 0x01, "UInt", x, "UInt", y)
        Sleep Integer(sleepTime * smoothness)
    }
}

;--------------------------------end--------------------------------
;   *   :   Fire the hotkey even if extra modifiers are being held down.
;   ~   :   When the hotkey fires, its key's native function will not be blocked (hidden from the system).
;   $   :   This is usually only necessary if the script uses the Send function to send the keys that comprise the hotkey itself,
;           which might otherwise cause it to trigger itself.
;   停止 空格键，鼠标中键，TAB键
Hotkey "*~$Space", "Off"
Hotkey "*~$MButton", "Off"
Hotkey "*~$t", "Off"

;   连续跳
;   ~   :   When the hotkey fires, its key's native function will not be blocked (hidden from the system). 
~F1::
{
    Hotkey "*~$Space", "Toggle"
    SoundPlay scriptDir "\..\music\12.mp3"
}

*~$Space::
{
    sleep 5
    loop
    {
        SpaceState := GetKeyState("Space","P")
        if Spacestate = 0
            break
        sleep 1
        Send "{Blind}{Space}"
    }
}

;   快速开火
~F2::
{
    Hotkey "*~$MButton", "Toggle"
    SoundPlay scriptDir "\..\music\13.mp3"
}

*~$MButton::
{
    sleep 10
    loop
    {
        SpaceState := GetKeyState("Mbutton","P")
        if SpaceState = 0
            break
        Sleep 1
        Send "{Blind}{LButton}"
    }
}

;   180度转身
F3::
{
    Hotkey "*~$t", "Toggle"
    SoundPlay scriptDir "\..\music\11.mp3"
}

*~$t::
{
    MouseMove 223*modifier, 0, 0, "R"
    loop 7
    {
        sleep 1
        MouseMove 432*modifier, 0, 0, "R"
    }
    sleep 200
}
;--------------------------------end--------------------------------
